from odoo import models, fields, api, _

from odoo.exceptions import UserError, ValidationError


class report_report_wtt_outbound_order(models.AbstractModel):
    _name = 'report.sb_stock_inherit.report_wtt_outbound_order'
    _description = 'WTT Outbound Order Report'

    @api.model
    def _get_report_values(self, docids, data=None):
        report = self.env['ir.actions.report']._get_report_from_name(
            'sb_stock_inherit.report_wtt_outbound_order')

        docs = self.env['stock.picking'].browse(docids)
        if docs.state in ('draft', 'cancel'):
            raise UserError(_('You cannot print a cancelled or draft picking.'))
        # if docs.picking_type_id.with_context(lang='zh_CN').name not in ['交货单']:
        #     raise UserError(_('Please select the delivery slip for printing.'))
        move = docs.move_ids_without_package.filtered(lambda x: x.product_id.detailed_type == 'product')
        flag = False
        for rec in move:
            categ_id = rec.product_id.get_top_category(rec.product_id.categ_id)
            if categ_id.code in ['BS', 'DF']:
                flag = True
        return {
            'doc_model': report.model,
            'docs': docs,
            'data': data,
            'flag': flag,
            'today': fields.Date.today(),
        }
